package tables

import (
	"github.com/GoAdminGroup/go-admin/context"
	"github.com/GoAdminGroup/go-admin/modules/db"
	"github.com/GoAdminGroup/go-admin/plugins/admin/modules/table"
	"github.com/GoAdminGroup/go-admin/template/types/form"
)

func GetSMSRecordTable(ctx *context.Context) table.Table {
	smsRecord := table.NewDefaultTable(table.DefaultConfigWithDriver("mysql"))

	info := smsRecord.GetInfo()
	info.SetFilterFormLayout(form.LayoutTwoCol)
	info.AddField("Id", "id", db.Int).
		FieldFilterable().
		FieldSortable()
	info.AddField("短信内容", "content", db.Varchar).
		FieldSortable()
	info.AddField("短信结果", "result", db.Varchar).
		FieldSortable()
	info.AddField("备注", "remark", db.Varchar).
		FieldFilterable().
		FieldSortable().
		FieldEditAble()
	info.AddField("创建时间", "created_at", db.Timestamp).
		FieldSortable()
	info.AddField("更新时间", "updated_at", db.Timestamp).
		FieldSortable()

	info.SetTable("sms_record").SetTitle("短信发送记录").SetDescription("SMSRecord")

	formList := smsRecord.GetForm()
	formList.AddField("Id", "id", db.Int, form.Default).
		FieldDisableWhenCreate()
	formList.AddField("短信内容", "content", db.Varchar, form.RichText)
	formList.AddField("发送结果", "result", db.Varchar, form.RichText)

	formList.AddField("备注", "remark", db.Varchar, form.Text)
	formList.AddField("创建时间", "created_at", db.Timestamp, form.Datetime).
		FieldDisableWhenUpdate().
		FieldHide().FieldNowWhenInsert()
	formList.AddField("修改时间", "updated_at", db.Timestamp, form.Datetime).
		FieldDisableWhenCreate().
		FieldHide().FieldNowWhenUpdate()

	formList.SetTable("sms_record").SetTitle("短信发送记录").SetDescription("SMSRecord")

	return smsRecord
}
